package com.zang.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZVerify
 * @since 2022/10/31 10:19
 * @see <a href="https://leetcode.cn/problems/path-sum/">...</a>
 **/
public class 路径总和 {

    public boolean hasPathSum(TreeNode root, int targetSum) {

        if (root==null) return false;

        return dfs(root,0,targetSum);
    }

    private boolean dfs(TreeNode root, int i,int targetSum) {

        if (root==null) return false;
        i = i+root.val;
        if (i==targetSum && root.left == null && root.right == null) return true;

        return dfs(root.left,i,targetSum) || dfs(root.right,i,targetSum);
    }


}
